package com.wuseguang.springcloud.dao.jdbc;

import com.wuseguang.springcloud.JdbcTemplate.BaseTemplate;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.stereotype.Repository;

import java.sql.PreparedStatement;
import java.sql.SQLException;


@Repository
public class CommonApplicationTemplate extends BaseTemplate {


    public int[] batchUpdate(String listSql, Integer[] ids, String schoolId, String teacherId) {
        return dao.batchUpdate(listSql, new BatchPreparedStatementSetter() {
            @Override
            public void setValues(PreparedStatement ps, int i) throws SQLException {
                Integer id = ids[i];
                ps.setInt(1, id);
                ps.setString(2, schoolId);
                ps.setString(3, teacherId);
            }

            @Override
            public int getBatchSize() {
                return ids.length;
            }
        });
    }
}
